package com.reason.gateway.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


/**
 * 主要做查询令牌的用
 * @author   yulongjun
 * @date 2020/6/30 7:39 下午
 */
@Service
public class OauthService {

    /**
     * 注入redisTemplate的模版类
     */
    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    /**
     * 从cookie中获取jti的值
     * @return
     */
    public String getJtiToCookie(ServerHttpRequest request){
        HttpCookie cookie = request.getCookies().getFirst("uid");
        if(cookie!=null){
            String jti = cookie.getValue();
            return jti;


        }
        System.out.println("您的cookie中没有jti的值");
        return null;

    }


    /**
     * 通过jti从redis中获取jwt的值
     * @param jti
     * @return
     */
    public String getJtiToRedis(String jti){

        String jwt = stringRedisTemplate.boundValueOps(jti).get();
        if(!StringUtils.isEmpty(jwt)){
            return jwt;

        }

        System.out.println("您的redis中没有查到该值");
        return null;

    }






}
